home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / SMTPCEMS.ZIP / READER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-15  |  2.9 KB  |  100 lines

  1. /*
  2. **  READER.C [edit EMAIL.H before compiling]
  3. **
  4. **  This program reads the specified email message
  5. **  and saves it to disk.
  6. */
  7.  
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "see.h"
  12. #include "email.h"
  13.  
  14. #define QUOTE 0x22
  15.  
  16. static char Buffer[1024];
  17.  
  18. void ErrorExit(int Code)
  19. {seeErrorText(Code,(LPSTR)Buffer,512);
  20.  printf("SEE Error %d: %s\n", Code, Buffer);
  21.  seeClose();
  22.  exit(1);
  23. }
  24.  
  25. void main(int argc, char *argv[])
  26. {int i, Code;
  27.  int Version; 
  28.  int Count;
  29.  int MsgNbr;
  30.  long MsgSize;
  31.  long BytesRead = 0;
  32.  if(argc!=3)
  33.    {printf("Usage: READER MsgNbr Filename\n");
  34.     printf("   eg: READER 1 message.mai\n");    
  35.     exit(1);
  36.    }
  37.    
  38.  /* display parameters */
  39.  
  40.  Version = seeStatistics(SEE_GET_VERSION);
  41.  printf("SEE4C Version %1x.%1x.%1x\n",0x0f&(Version>>8),0x0f&(Version>>4),0x0f&Version);
  42.  printf("Server : %s\n",(LPSTR)POP3_HOST_NAME);
  43.  printf("  User : %s\n",(LPSTR)POP3_USER_NAME);
  44.  printf("  Pass : %s\n",(LPSTR)POP3_PASSWORD);
  45.  printf("MsgNbr : %s\n",(LPSTR)argv[1] );
  46.  printf("SaveTo : %s\n",(LPSTR)argv[2]);
  47.  
  48.  MsgNbr = atoi(argv[1]); 
  49.  if((MsgNbr<1)||(MsgNbr>1000))
  50.    {printf("MsgNbr = %d out of range\n", MsgNbr);
  51.     exit(1);
  52.    }
  53.  /* define diagnostics log file */
  54.  ///seeStringParam(SEE_LOG_FILE, (LPSTR)"reader.log"); 
  55.  /* connect to POP3 server */
  56.  puts("Connecting...");
  57.  Code = seePop3Connect(
  58.     (LPSTR)POP3_HOST_NAME,             /* POP3 server */
  59.     (LPSTR)POP3_USER_NAME,             /* user */ 
  60.     (LPSTR)POP3_PASSWORD);             /* Password */
  61.  if(Code<0) ErrorExit(Code); 
  62.  /* get # messages waiting  */
  63.  puts("Getting message count...");
  64.  Count = seeGetEmailCount();                   
  65.  if(Count<0) ErrorExit(Count); 
  66.  printf("%d messages waiting.\n", Count);
  67.  /* read email message */
  68.  if((Count>=1)&&(MsgNbr<=Count))
  69.    {/* read message  */
  70.     MsgSize = seeGetEmailSize(MsgNbr);
  71.     if(MsgSize<0) ErrorExit((int)MsgSize);
  72.     printf("Message %d has %ld bytes\n", MsgNbr, MsgSize);    
  73.     /* turn off AUTO CALL driver */
  74.     seeIntegerParam(SEE_AUTO_CALL_DRIVER, 0); 
  75.     printf("Reading message %d...\n",MsgNbr);
  76.     ///Code = seeGetEmailFile(MsgNbr, argv[2], "c:\\temp", "c:\\temp");
  77.     Code = seeGetEmailFile(MsgNbr, argv[2], ".", ".");
  78.     if(Code<0) ErrorExit(Code);
  79.     /* run the driver */
  80.     for(i=0;;i++)
  81.       {Code = seeDriver();
  82.        if(Code<0) ErrorExit(Code);
  83.        if(((i%10)==9)||(Code==0))
  84.          {/* display progress on last call & every 10th call to seeDriver() */
  85.           BytesRead = (long) seeStatistics(SEE_GET_TOTAL_BYTES_READ);
  86.           printf("%ld bytes read.\r",BytesRead);
  87.          }
  88.        if(Code==0) break;
  89.        }
  90.     printf("\n");    
  91.     /* turn AUTO CALL back on for seeClose */
  92.     seeIntegerParam(SEE_AUTO_CALL_DRIVER, 1);
  93.     if(Code<0) ErrorExit(Code); 
  94.    }
  95.  else printf("No messages waiting\n");
  96.  seeClose();
  97. } /* end main */
  98.  
  99.  
  100.